//销售线索

const router = require('koa-router')();
const { salesLead } = require('../model');

// 添加数据
router.post('/salesLead/add', async (ctx, next) => {
  const {
    customerName,
    linkmanName,
    respectfully,
    role,
    department,
    cell,
    immobilization,
    fax,
    email,
    WeChat,
    qq,
    Vesting,
    clueState,
    serial,
    establish,
    previous,
    establishTime,
    updateTime,
    followTime,
    nextTime,
    notFollow,
    content,
    remind,
    remindWay,
    creation,
    id,
  } = ctx.request.body;
  const res = await salesLead.create({
    customerName,
    linkmanName,
    respectfully,
    role,
    department,
    cell,
    immobilization,
    fax,
    email,
    WeChat,
    qq,
    Vesting,
    clueState,
    serial,
    establish,
    previous,
    establishTime,
    updateTime,
    followTime,
    nextTime,
    notFollow,
    content,
    remind,
    remindWay,
    creation,
    id,
  });
  if (res) {
    ctx.body = {
      code: 200,
      msg: '添加成功',
      customerName,
      linkmanName,
      respectfully,
      role,
      department,
      cell,
      immobilization,
      fax,
      email,
      WeChat,
      qq,
      Vesting,
      clueState,
      serial,
      establish,
      previous,
      establishTime,
      updateTime,
      followTime,
      nextTime,
      notFollow,
      content,
      remind,
      remindWay,
      creation,
      id,
    };
  }
});

// 获取全部数据
router.post('/salesLead/getAll', async (ctx, next) => {
  const res = await salesLead.find();
  console.log(res);
  if (res) {
    ctx.body = {
      code: 200,
      msg: '获取全部数据成功',
      data: res,
    };
  }
});

// 修改数据
router.post('/salesLead/update', async (ctx, next) => {
  const {
    ids,
    customerName,
    linkmanName,
    respectfully,
    role,
    department,
    cell,
    immobilization,
    fax,
    email,
    WeChat,
    qq,
    Vesting,
    clueState,
    serial,
    establish,
    previous,
    establishTime,
    updateTime,
    followTime,
    nextTime,
    notFollow,
    content,
    remind,
    remindWay,
    creation,
    id,
  } = ctx.request.body;
  let res = await salesLead.updateOne(
    { _id: ids },
    {
      customerName,
      linkmanName,
      respectfully,
      role,
      department,
      cell,
      immobilization,
      fax,
      email,
      WeChat,
      qq,
      Vesting,
      clueState,
      serial,
      establish,
      previous,
      establishTime,
      updateTime,
      followTime,
      nextTime,
      notFollow,
      content,
      remind,
      remindWay,
      creation,
      id,
    }
  );
  if (res) {
    ctx.body = {
      code: 200,
      msg: '修改成功',
      data: res,
      department,
    };
  }
});

module.exports = router;
